package com.clkj.xiuzheng.controller.adv;

import com.clkj.xiuzheng.pojo.UserShopApply;
import com.clkj.xiuzheng.pojo.common.Result;
import com.clkj.xiuzheng.pojo.common.StatusCode;
import com.clkj.xiuzheng.service.ShopService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/commission")
@Api(value = "/commission", tags = {"佣金管理"})
@CrossOrigin
public class CommissionController {

    @Autowired
    private ShopService shopService;

    @ApiOperation(value = "获取佣金申请列表")
    @PostMapping("/listCommission")
    public Result listCommission(@RequestParam Integer pageSize,
                                 @RequestParam Integer pageNum,
                                 @RequestParam(required = false) Integer applySataus,
                                 @RequestParam(required = false) Integer userId) {
        try {
            PageInfo list =  shopService.listCommission(pageSize,pageNum,applySataus,userId);
            return new Result(true, StatusCode.OK,"查询成功",list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }

    @ApiOperation(value = "工人获取佣金记录列表(无分页)")
    @PostMapping("/MylistCommission")
    public Result MylistCommission(@RequestParam(required = false) Integer userId) {
        try {
           List<UserShopApply> list =  shopService.MylistCommission(userId);
            return new Result(true, StatusCode.OK,"查询成功",list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }
    @ApiOperation(value = "工人提交佣金申请")
    @PostMapping("/commitCommission")
    public Result commitCommission(@RequestParam Integer userId,
                                   @RequestParam Double applyMoney) {
        try {
            shopService.commitCommission(userId,applyMoney);
            return new Result(true, StatusCode.OK,"提交成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"提交失败");
        }
    }
    @ApiOperation(value = "工人佣金审核通过")
    @PostMapping("/passCommission")
    public Result passCommission(@RequestParam Integer applyId) {
        try {
            shopService.passCommission(applyId);
            return new Result(true, StatusCode.OK,"审核成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"审核失败");
        }
    }




}
